/*
 * Created by Gibbs on 2021/1/1.
 * Copyright (c) 2021 Gibbs. All rights reserved.
 */

#ifndef __GPLAYER_THREAD_H__
#define __GPLAYER_THREAD_H__

#include <thread>
#include <functional>

class XThread {
public:
    XThread(const std::string &name);

    virtual ~XThread();

    virtual bool start();

    virtual void pause();

    virtual void resume();

    virtual bool stop();

    void join();

    bool isAlive() { return mRunning; }

    bool isPausing() { return mPausing; }

    void setFunction(std::function<void(void)> func) { mFunc = func; }

protected:
    volatile bool mRunning = false;
    volatile bool mPausing = false;
    std::thread *mThread = nullptr;
    std::function<void(void)> mFunc;
    std::string threadName;
};

#endif //__GPLAYER_THREAD_H__
